package com.ymatou.iapi.trading.sellerquery2.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.seller.trading.api.parameter.ExistsResponse;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.common.enums.LogisticsTypeEnum;
import com.ymttest.common.enums.OrderStatusEnum;
import com.ymttest.common.order.sellerquery2.Convertor;
import com.ymttest.common.order.sellerquery2.ExportOrderInfo;
import com.ymttest.common.order.sellerquery2.TimeRange;
import com.ymttest.common.order.sellerquery2.bean.ExistsSellerExportedOrderInfosBean;
import com.ymttest.common.order.sellerquery2.model.SellerExportOrderQueryModel;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * @date 2016-06-28
 * @author songyefeng
 * @desc 是否存在卖家订单导出信息
 */
@TestSuite
public class Ts_ExistsSellerExportedOrderInfos {

	private static ExistsSellerExportedOrderInfosBean request;
	// private static
	// com.ymatou.query.seller.trading.api.service.ExistsSellerExportedOrderInfosCall
	// call;
	private static com.ymatou.iapi.trading.sellerquery2.service.ExistsSellerExportedOrderInfosCall call;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("是否存在卖家订单导出信息");
	}

	@Before
	public void caseUp() {
		request = new ExistsSellerExportedOrderInfosBean();
		// call = new
		// com.ymatou.query.seller.trading.api.service.ExistsSellerExportedOrderInfosCall();
		call = new com.ymatou.iapi.trading.sellerquery2.service.ExistsSellerExportedOrderInfosCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verify() {
		// get the expect result with expectedExistsResponse
		ExistsResponse expectedExistsResponse = new ExistsResponse();
		ConstructExpectedResponse(expectedExistsResponse);
		ExistsResponse actualExistsResponse = call.getData();
		DataUtil.verifyEquals(expectedExistsResponse.isExists(), actualExistsResponse.isExists(), "验证Exists");
	}

	private void ConstructExpectedResponse(ExistsResponse expectedExistsResponse) {
		Process(expectedExistsResponse);
	}

	private void Process(ExistsResponse expectedExistsResponse) {
		SellerExportOrderQueryModel model = Convertor.SellerExportOrderRequestArguments(request);
		boolean exists = ExistsSellerExportedOrderInfosResponseProcessor(model);
		expectedExistsResponse.setExists(exists);
	}

	private boolean ExistsSellerExportedOrderInfosResponseProcessor(SellerExportOrderQueryModel model) {
		return ExportOrderInfo.GetExportSellerOrderInfoExistsSqlCommand(model);
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_001() {
		Logger.start(true, "获取是否存在卖家订单导出信息成功");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-7, YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_002() {
		Logger.start(true, "是否存在卖家订单导出信息, 测试paidTime筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-4, YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_003() {
		Logger.start(true, "是否存在卖家订单导出信息, 测试订单状态为17的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-4, YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.SellerAccept.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_004() {
		Logger.start(true, "是否存在卖家订单导出信息, paidTime的end为空");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.AccountPaid.getValue());
			request.setOrderStatus(orderStatus);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_005() {
		Logger.start(true, "是否存在卖家订单导出信息, paidTime的start为空");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.AccountPaid.getValue());
			request.setOrderStatus(orderStatus);
			TimeRange paidTime = new TimeRange();
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_008() {
		Logger.start(true, "是否存在卖家订单导出信息, 订单状态包含1,2,3,4,12,13,18,17");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.OrderEstablish.getValue());
			orderStatus.add(OrderStatusEnum.AccountPaid.getValue());
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			orderStatus.add(OrderStatusEnum.Received.getValue());
			orderStatus.add(OrderStatusEnum.UserAcceptCancel.getValue());
			orderStatus.add(OrderStatusEnum.SellerAcceptCancel.getValue());
			orderStatus.add(OrderStatusEnum.SystemCancel.getValue());
			orderStatus.add(OrderStatusEnum.SellerAccept.getValue());
			request.setOrderStatus(orderStatus);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_012() {
		Logger.start(true, "是否存在卖家订单导出信息, 测试配送方式的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes.add(LogisticsTypeEnum.China.getValue());
			logisticsTypes.add(LogisticsTypeEnum.AuthenticatedDirectDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.SailProtect.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange paidTime = new TimeRange();
			paidTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			paidTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setPaidTime(paidTime);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_013() {
		Logger.start(true, "是否存在卖家订单导出信息, 测试配送方式的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			request.setSellerId(SellerId);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes.add(LogisticsTypeEnum.SailProtect.getValue());
			logisticsTypes.add(LogisticsTypeEnum.AuthenticatedDirectDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.PackageDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.US.getValue());
			logisticsTypes.add(LogisticsTypeEnum.BondedDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.XloboBondedDelivery.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_014() {
		Logger.start(true, "获取是否存在卖家订单导出信息失败, SellerId为空");
		try {
			request.setSellerId(null);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes.add(LogisticsTypeEnum.SailProtect.getValue());
			logisticsTypes.add(LogisticsTypeEnum.AuthenticatedDirectDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.PackageDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.US.getValue());
			logisticsTypes.add(LogisticsTypeEnum.BondedDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.XloboBondedDelivery.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("400", call.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_015() {
		Logger.start(true, "获取是否存在卖家订单导出信息成功, SellerId不存在");
		try {
			request.setSellerId(404);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes.add(LogisticsTypeEnum.SailProtect.getValue());
			logisticsTypes.add(LogisticsTypeEnum.AuthenticatedDirectDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.PackageDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.US.getValue());
			logisticsTypes.add(LogisticsTypeEnum.BondedDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.XloboBondedDelivery.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_016() {
		Logger.start(true, "获取是否存在卖家订单导出信息失败, SellerId为0");
		try {
			request.setSellerId(404);
			List<Integer> logisticsTypes = new ArrayList<Integer>();
			logisticsTypes.add(LogisticsTypeEnum.SailProtect.getValue());
			logisticsTypes.add(LogisticsTypeEnum.AuthenticatedDirectDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.PackageDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.US.getValue());
			logisticsTypes.add(LogisticsTypeEnum.BondedDelivery.getValue());
			logisticsTypes.add(LogisticsTypeEnum.XloboBondedDelivery.getValue());
			request.setLogisticsTypes(logisticsTypes);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-3, YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ExistsSellerExportedOrderInfos_017() {
		Logger.start(true, "是否存在卖家订单导出信息, 测试buyernickname的筛选");
		try {
			int SellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			String buyerNickName = String.valueOf(EnvSetup.getData("BuyUserName"));
			request.setSellerId(SellerId);
			request.setBuyerNickName(buyerNickName);
			TimeRange createdTime = new TimeRange();
			createdTime.setBegin(YMTDateUtil.getBeforeOrNextDay(-60, YMTDateUtil.YMDTHMS_STRING));
			createdTime.setEnd(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			request.setCreatedTime(createdTime);
			List<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(OrderStatusEnum.Shipped.getValue());
			request.setOrderStatus(orderStatus);
			call.setData(request);
			call.callService();
			Logger.verifyEquals("200", call.getCode(), "验证code");
			verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}